<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<title>Title</title>
		<style type="text/css">
			* {
				margin: 0;
				padding: 0;
			}
			img {
				vertical-align: top;
			}
			.main {
				margin: 10px auto 0;
				width: 1000px;
			}
			.fixed {
				position: fixed;
				top: 0;
				left: 0;
			}
		</style>
		<script src="../jquery-1.12.4.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			$(function(){
				$(window).scroll(function(){
					//判断卷去的高度超过topPart的高度
					//1.让navBar有固定定位
					//2.让mainPart有一个marginTop
					if($(window).scrollTop() >= $(".top").height()){
						$(".nav").addClass("fixed");
						$(".main").css("marginTop",$(".nav").height() + 10);
					}else {
						$(".nav").removeClass("fixed");
						$(".main").css("marginTop",10);
					}
				});
			});
		</script>
	</head>
	<body>
		<div class="top" id="topPart"><img src="images/top.png" alt=""></div>
		<div class="nav" id="navBar"><img src="images/nav.png" alt=""></div>
		<div class="main" id="mainPart"><img src="images/main.png" alt=""></div>
	</body>
</html>